import { createRouter, createWebHistory } from "vue-router"
import layout from '../views/layout.vue'

const routerContext = require.context('./modules', true, /\.js$/)
const IndexRoute = {
  path: '/',
  component: layout,
  meta: {},
  children: []
}
routerContext.keys().forEach(route => {
  if (route.startsWith('./index')) {
    return
  }
  const routerModule = routerContext(route)
  IndexRoute.children = [...IndexRoute.children, ...(routerModule.default || routerModule)]
})
let routes = [
  IndexRoute
]
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes: routes
})
export default router
